﻿using Excel = ClosedXML.Excel;

namespace dgmobile
{
  public static class XL
  {
    private static Excel.XLWorkbook temp = null;

    public static void MonthlyReport()
    {
      //File creation
      temp = new Excel.XLWorkbook();

      //Table creation
      System.Data.DataTable dt = DB.ListData(true);
      var lista = temp.Worksheets.Add(dt, "Lista");

      //Extras
      //ExtraReport(temp);

      //Creates save dialog to save created file to My Documents folder.
      string dir = System.Environment.GetFolderPath(System.Environment.SpecialFolder.MyDocuments);
      System.Windows.Forms.SaveFileDialog sv = new System.Windows.Forms.SaveFileDialog();
      sv.FileName = "Relatório Mensal de Atividades do DG.xlsx";
      sv.Filter = "Planilha do Microsoft Excel (*.xlsx)|*.xlsx|Todos os arquivos (*.*)|*.*";
      sv.Title = "Exportar relatório mensal de atividades para planilha do Excel.";
      sv.InitialDirectory = dir;
      sv.RestoreDirectory = true;

      if(sv.ShowDialog() == System.Windows.Forms.DialogResult.OK)
      {
        temp.SaveAs(sv.FileName);
        System.Diagnostics.Process.Start(sv.FileName);
      }
    }

    private static void ExtraReport(Excel.XLWorkbook temp)
    {
      var atendimento = temp.Worksheets.Add("Atendimento");
      var melhoria = temp.Worksheets.Add("Melhoria");
      var bd = temp.Worksheets.Add("BD");
      var os = temp.Worksheets.Add("OS");
    }
  }
}